<?php
require("bases.php");

class sites extends bases {

	public function __construct(){
		parent::__construct();
		try{
			$this->fmenu = $this->controller = "sites";
			$this->position_one = array("text"=>"网站通用管理", "url"=>spUrl($this->controller, "config"));
		}catch(Exception $e){

		}
	}
	
	function config() {
		spClass('admin')->checkadmin(1);
		if($_SERVER['REQUEST_METHOD'] == 'POST') {
			$copyright_info = $this->spArgs('copyright_info');
			if($copyright_info != ''){
				$_POST['copyright_info'] = str_replace(URL_ROOT.'/upload/', 'upload/', $copyright_info);
			}
			unset($_POST['isAjax']);
			$str = "<?php\r\n\$app_config = ".var_export($_POST, true).';';
			$fp = fopen(APP_PATH . DS . 'app_config.php', 'w');
			if (fputs($fp,$str)) {
				fclose($fp);
				$url = spUrl($this->controller, "config");
				$message = array('msg'=>'网站配置修改成功！','result'=>1, 'url'=>$url);
				echo json_encode($message);
				exit();
			}else{
				fclose($fp);
				$message = array('msg'=>'网站配置修改失败！','result'=>0);
				echo json_encode($message);
				exit();
			}
		}
		global $app_config;
		if($app_config['copyright_info']!=''){
			$copyright_info = str_replace("upload/", URL_ROOT."/upload/", $app_config['copyright_info']);
		}
		$this->copyright_info = $copyright_info;
		$this->position_last = $this->formtitle = array("text"=>"网站设置");
		$this->saveurl = spUrl($this->controller, "config");
	}
	
	public function change_entrance(){
		$id = $this->spArgs("id");
		$_SESSION["sys_entrance"] = spClass("entrance")->getByMark($id);
		echo json_encode(array("reload"=>1, "result"=>1));
		exit();
	}
	
	function htmlupdate(){
		import("Common.php");
		$articlestyle = spClass('articlestyle');
		$this->saveurl = str_replace(NOW_PATH."/", "../", spUrl("main", "htmlupdate"));
		$list_type = array();
		$list_temp = $articlestyle->findAll(array("frontdisplay"=>1), "sid asc", "sid, sname, parentid");
		$list_rs = Common::TypeList($list_type, $list_temp, "sid", 0, 1, "parentid");
		$this->list_rs = $list_rs;
	}
	
	function htmlupdate_adv(){
		import("Common.php");
		$articlestyle = spClass('articlestyle');
		$this->saveurl = str_replace(NOW_PATH."/", "../", spUrl("main", "htmlupdate"));
		$list_type = array();
		$list_temp = $articlestyle->findAll(array("frontdisplay"=>1), "sid asc", "sid, sname, parentid");
		$list_rs = Common::TypeList($list_type, $list_temp, "sid", 0, 1, "parentid");
		$this->list_rs = $list_rs;
	}
	
	function sitemapupdate(){
		spClass('admin')->checkadmin(1);
		$this->saveurl = str_replace(NOW_PATH."/", "../", spUrl("main", "sitemapupdate"));
		$this->position_last = $this->formtitle = array("text"=>"网站地图");
	}
	
	function unhtml(){
		$this->saveurl = str_replace(basename(APP_PATH)."/", "", spUrl($this->controller, "unhtml"));
	}
}
?>